package com.example.servlet;

import com.example.dao.NovelDao;
import com.example.domain.Novel;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@WebServlet("/AdminNovelAddServlet")
public class AdminNovelAddServlet extends HttpServlet {
    public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
    {
        request.setCharacterEncoding("utf-8");
        String title = request.getParameter("title");
        String author = request.getParameter("author");
        String description = request.getParameter("description");
        String cover_image_url = request.getParameter("cover_image_url");
        String category = request.getParameter("category");
        String status = request.getParameter("statu_s");
//        String update_time = request.getParameter("update_time");
        Novel novel = new Novel(title,author,description,cover_image_url,category,status,"1",0);
        int affectedRow = new NovelDao().addNovel(novel);
        if(affectedRow>0){
            request.setAttribute("msg","添加成功");
        }else{
            request.setAttribute("msg","添加失败");
        }
        request.getRequestDispatcher("admin_NovelAdd.jsp").forward(request,response);
    }
    public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
    {
        doGet(request, response);
    }
}
